const { merge } = require('webpack-merge')
const dev = require('./webpack.dev')
const path = require('path')
const prod = require('./webpack.prod')
const htmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const option = {
    entry: "./src/index.js",
    output: {
        path: path.resolve(__dirname, process.cwd(), 'dist'),
        filename: 'bundle.js',
    },

    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    "style-loader",
                    {
                        loader: "css-loader",
                        options: {
                            importLoaders: 1
                        }
                    },
                    {
                        loader: "postcss-loader",
                    }
                ]
            }
        ]
    },
    plugins: [
        new htmlWebpackPlugin({
            title: "132",
            template: "./public/index.html"
        }),
    ]
}

module.exports = (env) => {
    const isProduction = !!env.production
    const config = isProduction ? prod : dev
    return merge(option, config)
}